layui.use(['form','layer','upload','laydate','layedit'],function(){
        var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;

    var laydate = layui.laydate;

    var commentContent;
    //富文本编辑器
    layui.use('layedit', function(){
        var layedit = layui.layedit;
        layedit.set({
            uploadImage: {
                url: '/upload/editPicUpload' //接口url
                ,type: 'post' //默认post
            }
        });
        commentContent=layedit.build('commentContent',{
            height: 160 //设置编辑器高度
        }); //建立编辑器
    });


    //获取路径中的参数
    function GetRequest() {
        var url = location.search;         //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            var strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
    //回显数据
    var request = GetRequest();
    $.get("/produceComment/" + request.id,function (data) {

        var date = new Date(data.commentTime);
        laydate.render({
            elem: '#commentTime'
            ,value: date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() //必须遵循format参数设定的格式  + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds()
        });

        $(".id").val(data.id);
        $(".produceId").val(data.produceId);
        $(".userId").val(data.userId);
        $(".thumbsUpCount").val(data.thumbsUpCount);
        $(".commentContent").val(data.commentContent);
        commentContent=layui.layedit.build('commentContent',{
            height: 160 //设置编辑器高度
        });
        $("#pic").val(data.pic);
        $("#uploadImage").attr("src",data.pic);



        for(var i=0,flag=data.commentStatus;i<2;i++) {
            if (flag == 1) {
                if (i == 0) {
                    $("#commentStatus").append('<option selected="selected" value="1">不可见</option>');
                }
                else {
                    $("#commentStatus").append('<option value="1">不可见</option>');
                }
                flag = 0;
            } else {
                if (i == 0) {
                    $("#commentStatus").append('<option selected="selected" value="0">可见</option>');
                }
                else {
                    $("#commentStatus").append('<option value="0">可见</option>');
                }
                flag = 1;
            }
        }
            form.render('select');

    });



    form.on("submit(editMerchant)",function(data){
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});

         $.post("/produceComment/edit",{
             userId : $(".userId").val(),
             produceId : $(".produceId").val(),
             commentStatus : $(".commentStatus").val(),
             pic : data.field.pic,
             thumbsUpCount : data.field.thumbsUpCount,
             commentContent : layui.layedit.getContent(commentContent),

            // newsTime : submitTime, 由后台添加时间,而这里评论时间不能更改
             id : $(".id").val(),
         },function(res){

         })
        setTimeout(function(){
            top.layer.close(index);
            top.layer.msg("用户修改成功！");
            layer.closeAll("iframe");
            //刷新父页面
            parent.location.reload();
        },2000);
        return false;
    })

})